package com.sun.showcase.biz.sms;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.sun.showcase.client.enums.SmsTypeEnum;

public class SmsClient {

	private static void sendSms(String phone, String content,String type) {
		
		DefaultProfile profile = DefaultProfile.getProfile("default", "LTAI4FvKcY6Lpu9xBuqcLktV", "HyYh31zDycfjXKsTpZ6ML7T1bwBtRv");
		
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        
        request.setMethod(MethodType.POST);
        
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "九牧农场");
        request.putQueryParameter("TemplateCode", SmsTypeEnum.getTemplateBy(type));

        
        request.putQueryParameter("TemplateParam", content);
        
        try{
        	
            CommonResponse response = client.getCommonResponse(request);
            
            System.out.println(response.getData());

        }catch(ServerException e){
        	
            e.printStackTrace();
            
        }catch(ClientException e){
        	
            e.printStackTrace();
        }

	}

	
	public static void send(String phone,String smsCode,String type) {
		
		String content = "{\"code\":\""+smsCode+"\"}";
		
		sendSms(phone, content, type);
	}
	
}
